﻿using System;
using System.Configuration;
using System.Data.EntityClient;
using System.Data.Objects;
using System.IO;
using System.Linq;
using System.Transactions;
using System.Web.Mvc;
using MeresModeling;
using Orchard.Themes;

namespace Meres.Controllers
{
    [Themed]
    public class MeresMainController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Mode = System.Configuration.ConfigurationManager.AppSettings["mode"];
            return View("MeresMainView");
        }


        public PartialViewResult StartPage()
        {
            return PartialView("StartPage");
        }

        public PartialViewResult MyScheduler()
        {
            return PartialView("SchedulerView");
        }

        public PartialViewResult PdfViewer()
        {
            return PartialView("PdfViewer");
        }

        private static MeresModel _model;
        public static MeresModel Model
        {
            get
            {
                _model = new MeresModel(GetConnectionString());
                return _model;
            }
        }

        public static string GetConnectionString()
        {
            return ConfigurationManager.ConnectionStrings["MeresModel"].ConnectionString.Replace(
                        "|ModuleDir|", ModuleDir).Replace("res://*",
                                                          "res://" + typeof(MeresModel).Assembly.FullName);
        }

        public static string ModuleDir
        {
            get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", "Meres"); }
        }
    }
}
